package com.shanjupay.merchant;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shanjupay.common.util.EncryptUtil;
import com.shanjupay.merchant.api.MerchantService;
import com.shanjupay.merchant.api.dto.MerchantDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class TokenTemp {

    @Autowired
    private MerchantService  merchantService;

    /**
     *  生成token ， 指定
     *
     */
    @Test
    public void  testCreateToken()  {
        // 填写用于测试的商户id
        Long merchantId =  1355486018555367426L;
        MerchantDTO merchantDTO = merchantService.queryById(merchantId);

        System.out.println("查询到的结果为："+ JSON.toJSONString(merchantDTO));

        JSONObject token = new JSONObject();
        token.put("mobile",merchantDTO.getMobile());
        token.put("user_name",merchantDTO.getUsername());
        token.put("merchantId",merchantId);

        String strToken = JSON.toJSONString(token);

        System.out.println("strToken = " + strToken);

        String encodeBase64 = EncryptUtil.encodeBase64(strToken.getBytes());

        System.out.println("加密结果为：" + encodeBase64);

        String jwt_token = "Bearer " + encodeBase64;

        System.out.println(jwt_token);
    }
}
